package day08Test;

import java.util.Random;
import java.util.Scanner;

public class Test3 {
    public static void main(String[] args) {
        int[] arr2 = userInputNumber();
        int[] arr = createNumber();
        for (int i = 0; i < arr.length; i++) {
            System.out.print(arr[i] + " ");
        }
        System.out.println();
        int redCount = 0;
        int blueCount = 0;
        for (int i = 0; i < arr.length-1; i++) {
            for (int j = 0; j < arr2.length-1; j++) {
                boolean flag =flag(arr2,arr[i]);
                if (flag){
                    redCount++;
                    break;
                }
            }
        }
        if (arr[arr.length-1] == arr2[arr2.length-1]) {
            blueCount++;
        }
        System.out.println("红球中奖个数为" + redCount);
        System.out.println("蓝球中奖个数为" + blueCount);
    }

    public static int[] createNumber() {
        int[] arr = new int[7];
        Random r = new Random();
        for (int i = 0; i < arr.length - 1; ) {
            int redNumber = r.nextInt(33) + 1;
            boolean flag = flag(arr,redNumber);
            if (!flag){
                arr[i] = redNumber;
                i++;
            }
        }
        int blueNumber = r.nextInt(16) + 1;
        arr[arr.length - 1] = blueNumber;
        return arr;
    }

    public static int[] userInputNumber(){
        Scanner sc = new Scanner(System.in);
        int[] newArr = new int[7];
        for (int i = 0; i < newArr.length - 1; ) {
            System.out.println("请输入第" + (i + 1) + "个红球号码");
            int redNumber = sc.nextInt();
            if (redNumber >= 0 && redNumber <= 33){
                boolean flag =flag(newArr,redNumber);
                if (!flag){
                    newArr[i] = redNumber;
                    i++;
                }else {
                    System.out.println("输入重复");
                }

            }else {
                System.out.println("输入超出范围");
            }
        }
        System.out.println("请输入蓝球号码");
        int blueNumber = sc.nextInt();
        while (true) {
            if (blueNumber >= 0 && blueNumber <= 16){
                newArr[newArr.length-1] = blueNumber;
                break;
            }else {
                System.out.println("输入超出范围");
            }
        }
        return newArr;
    }

    public static boolean flag(int[] arr,int number) {
        for (int i = 0; i < arr.length - 1; i++) {
            if (arr[i] == number){
                return true;
            }
        }
        return false;
    }
}
